﻿@model Sheng.WeixinConstruction.Management.Shell.Models.DistributedCouponViewModel

@{
    ViewBag.MainMenu = "Member";
    ViewBag.LeftMenu = "Coupon";

    Layout = "~/Views/Shared/_Layout.cshtml";
}

<style type="text/css">
    .divBaseSettingsTitle {
        margin-top: 25px;
        margin-left: 10px;
        margin-right: 10px;
    }
</style>



<script language="javascript">

    var _couponId = getQueryString("couponId");

    //当前页
    var _currentPage = 1;

    $(document).ready(function () {
        if (_online == false)
            return;

        loadData();

        $("[keyenter]").keypress(function (e) {
            if (e.keyCode == 13) {
                loadData();
            }
        });
    });

    function loadData(targetPage) {
        var loadLayerIndex = layer.load(0, {
            shade: [0.2, '#fff']
        });

        var args = new Object();
        args.Page = targetPage || 1;
        args.CouponId = _couponId;
        args.SerialNumber = $("#txtSearch_SerialNumber").val();
        args.MemberNickName = $("#txtSearch_MemberNickName").val();
        args.Status = $("#selectSearch_Status").val();
        if (args.Status == "-1") {
            args.Status = null;
        }

        $.ajax({
            url: "/Api/Coupon/GetDistributedCouponList",
            type: "POST",
            dataType: "json",
            data: JSON.stringify(args),
            success: function (data, status, jqXHR) {
                // alert(data);

                layer.close(loadLayerIndex);
                if (data.Success) {
                    var resultObj = data.Data;

                    _currentPage = resultObj.Page;

                    //alert(JSON.stringify(resultObj));
                    var gettpl = document.getElementById('tableTemplate').innerHTML;
                    laytpl(gettpl).render(resultObj.ItemList, function (html) {
                        document.getElementById('divTableBodyContainer').innerHTML = html;
                        fitTable();
                    });

                    laypage({
                        skin: 'yahei',
                        cont: document.getElementById('divPagingContainer'),
                        pages: resultObj.TotalPage, //总页数
                        curr: resultObj.Page, //当前页
                        groups: 7, //连续显示分页数
                        jump: function (obj, first) {
                            if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
                                loadData(obj.curr);
                            }
                        }
                    });

                } else {
                    layerAlert(data.Message);
                }
            },
            error: function (xmlHttpRequest) {
                layer.close(loadLayerIndex);
                alert("Error: " + xmlHttpRequest.status);
            }
        });
    }

    function loadDataAndCloseLayer(layerIndex) {
        layer.close(layerIndex);
        loadData();
    }

    function loadDataOnPageAndCloseLayer(layerIndex) {
        layer.close(layerIndex);
        loadData(_currentPage);
    }

    function scrollHeader() {
        // alert(divTableBodyContainer.scrollLeft);
        var ml = 0 - divTableBodyContainer.scrollLeft;
        document.getElementById("tableHeader").style.cssText = "margin-left:" + ml + "px;";
    }

    function fitTable() {
        $("#tableBody").width($("#tableHeader").width());

        $("#tableHeader tr:first").each(function (n, value) {
            $(this).find("td").each(function (n, value) {
                $("#tableBody tr:first td:eq(" + n + ")").width(value.width)
            });
        });
    }

    function distribute() {
        layer.open({
            type: 2,
            area: ['640px', '550px'], //宽高
            closeBtn: false,
            title: "",
            shift: _layerShift,
            content: 'CouponDistribute?couponId=' + _couponId
        });
    }


</script>

<script id="tableTemplate" type="text/html">

    <table id="tableBody" border="0" cellspacing="0" cellpadding="0">

        {{# for(var i = 0, len = d.length; i < len; i++){ }}
        <tr>
            <td>{{ d[i].MemberNickName }}</td>
            <td height="35">
            @*<a href="javascript:void(0)" onclick="modify('{{ d[i].Id }}')">{{ d[i].SerialNumber }}</a>*@
            {{ d[i].SerialNumber }}
            </td>
            <td>{{ d[i].DistributeTime }}</td>
            <td>{{ d[i].DistributeUserName }}</td>
            <td>
                {{# if(d[i].LimitedTime != null ){  var time = new Date(d[i].LimitedTime.replace(/-/g,"/")).format("yyyy-MM-dd ");}}{{ time }}{{# } }}
            </td>
            <td>
                {{# if(d[i].Status == 0){ }}
                未核销
                {{# }else if(d[i].Status == 1){ }}
                已核销
                {{# }else{ }}
                未知：{{ d[i].Status }}
                {{# } }}
            </td>
            <td>
                {{# if(d[i].ChargeTime != null ){}}
                {{ d[i].ChargeTime }}
                {{# } }}
            </td>
            <td>
                {{# if(d[i].ChargeUserName != null ){}}
                {{ d[i].ChargeUserName }}
                {{# } }}
            </td>
        </tr>
        {{# } }}

    </table>

</script>

<div class="divBaseSettingsTitle">
    <table border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td class=" font_black_22">@Model.Coupon.Name</td>
            <td width="35">&nbsp;</td>
            <td valign="bottom"><a href="/Member/Coupon">[返回]</a></td>
        </tr>
    </table>
</div>

<div class="divDotLine" style="margin-top:10px; width:400px;"></div>

<div style="margin-top:16px;">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td bgcolor="#F6F6F6">
                <div style="padding:10px;">
                    <table width="100%" border="0" cellspacing="0" cellpadding="8">
                        <tr>
                            <td width="80">卡券号：</td>
                            <td width="220"> <input id="txtSearch_SerialNumber" name="txtSearch_SerialNumber" type="text" class="input_16" style="width:200px;" /></td>
                            <td width="80">&nbsp;</td>
                            <td width="220">&nbsp;</td>
                            <td>&nbsp;</td>
                            <td width="100" align="right">
                                <span style=" margin-top:20px;">
                                    <input name="btnSearch" type="button" class="btn_blue" id="btnSearch" value="查询" onclick="loadData()" />
                                </span>
                            </td>
                        </tr>
                        <tr>
                            <td>会员昵称：</td>
                            <td><input id="txtSearch_MemberNickName" name="txtSearch_MemberNickName" type="text" class="input_16" style="width:200px;" /></td>
                            <td>状态：</td>
                            <td>
                                <select id="selectSearch_Status" name="selectSearch_Status" class="input_16" style="width:200px;">
                                    <option value="-1">全部</option>
                                    <option value="0">未核销</option>
                                    <option value="1">已核销</option>
                                </select>
                            </td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
                    </table>

                </div>
            </td>
        </tr>
        <tr style="height:5px;background-image:url(/Content/Images/searchArea_bottom.jpg);background-repeat: repeat-x;">
            <td></td>
        </tr>
    </table>

</div>

<div style=" margin-top:20px;">
    <input name="btnCreate" type="button" class="btn_blue" id="btnCreate" value="派 发" onclick="distribute()" />
    @*<div style="float:right">
            <input name="btnRemove" type="button" class="btn_red" id="btnRemove" value="删 除" style="margin-left:5px;" onclick="removeData()" />
        </div>*@
</div>


<div style=" margin-top:20px">
    <div style="overflow:hidden; padding-left:20px;" class="tableHeader">

        <table id="tableHeader" border="0" cellspacing="0" cellpadding="0" width="1460" height="47">
            <tr>
                <td width="220">会员昵称</td>
                <td width="200">卡券号</td>
                <td width="180">派发时间</td>
                <td width="200">派发人</td>
                <td width="180">有效期</td>
                <td width="100">是否核销</td>
                <td width="180">核销时间</td>
                <td width="200">核销人</td>
            </tr>
        </table>

    </div>



    <div style=" margin-top:10px">
        <!--div必须要设置height，否则滚动条出不来-->
        <div id="divTableBodyContainer" style="overflow:auto; height:100%;; padding-left:20px;" onscroll="scrollHeader()">
            <!--table必须要有一个确切的宽度，否则无法超出div-->
            @*<table id="tableBody" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td height="35">斗战圣佛1988</td>
                        <td><a href="#">1151111021237</a></td>
                        <td>2015-10-9 15:12:13</td>
                        <td>陈老三</td>
                        <td>2015-10-9 15:12:13</td>
                        <td>否</td>
                        <td>莫大毛</td>
                        <td>2015-10-9 15:12:13</td>
                    </tr>
                </table>*@
        </div>

    </div>

</div>
<div style="height:1px; margin-top:5px; background-color:#cccccc">

</div>

<div id="divPagingContainer" style=" margin-top:20px; margin-bottom:20px;text-align:right; ">

</div>


